文章目录
  1. 1. 测试代码
  2. 2. 报错及解决办法
  3. 3. 添加第三方源

我的配置:Centos 6.4 + opencv 2.4.8 + ffmpeg 2.8.5

最近在用opencv的VideoCapture读取rtsp摄像头,首先找到以下代码,想测试一下:

测试代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;

/**
* Created by jkyan on 1/26/16.
*/

public class OpenCVRTSPReader {

public static void main(String[] args) {
System.load("/lib/linux64_opencv_java248.so");
VideoCapture capture = new VideoCapture("rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp");

Mat image=new Mat();
double propid=0;
capture.open("rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp");
int i = 0;
if (capture.isOpened()) {
System.out.println("Video is captured");
int x=0;
while (x<18) {
x=x+1;
propid=capture.get(x);
System.out.println("Property Id is " + x + " value ="+ propid);
}
// grab 10 frames as a test
while (i < 10) {
try {
//capture.retrieve(image); //same results as .read()
capture.read(image);
//Highgui.imwrite("camera"+i+".jpg", image);
System.out.println("read a frame at "+ i);
} catch (Exception e) {
e.printStackTrace();
}
i=i+1;

}
} else {
System.out.println("Camera can not be opened!");
}
capture.release();
System.out.println("VideoCapture is released");
System.exit(0);
}
}

报错及解决办法

但是运行时直接报错(在已经安装了OpenCV的情况下,Opencv的安装教程参考,同时安装了ffmpeg, ffmpeg的安装教程参考), Your GStreamer installation is missing a plug-in, 报错内容如下:

1
GStreamer Plugin: Embedded video playback halted; module decodebin20 reported: Your GStreamer installation is missing a plug-in.

说是缺少插件,找到的解决办法基本上都是安装以下包:

1
yum install gstreamer-{ffmpeg,plugins-{bad,good,ugly}}

但是直接使用yum安装会提示这些包找不到,因为他们并不在官方源中,因此需要添加第三方源

添加第三方源

我找到的解决办法是添加rpmfusion源,参考教程为:http://rpmfusion.org/Configuration
直接直接以下命令即可安装:

1
su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm'

然后更新yum:

1
2
yum clean all
yum makecache

但是我添加了之后,gstreamer-ffmpeg仍然装不上,会报缺少liborc.so.0.4这个库
最后找到这个网站:http://pkgs.org/centos-6/linuxtech/liborc-devel-0.4.14-1.el6.x86_64.rpm.html
里面有liborc的包,因此按照其教程,在/etc/yum.repos.d/目录中新建linuxtech.repo,文件内容如下:

1
2
3
4
5
6
[linuxtech]
name=LinuxTECH
baseurl=http://pkgrepo.linuxtech.net/el6/release/
enabled=1
gpgcheck=1
gpgkey=http://pkgrepo.linuxtech.net/el6/release/RPM-GPG-KEY-LinuxTECH.NET

同样更新一下:

1
yum makecache

然后安装liborc:

1
yum install liborc-devel

再接着安装gstreamer-ffmpeg和其他的gstreamer-plugins-{bad,good,ugly} 可顺利装上:

1
yum install gstreamer-{ffmpeg,plugins-{bad,good,ugly}}

然后再去运行上述代码,可以完美运行。
结束。






转载请标明文章出处。本文内容为实践后的原创整理,如果侵犯了您的版权,请联系我进行删除,邮件:yanhealth@163.com

参考:
[1] http://ubuntuforums.org/archive/index.php/t-1730395.html
[2] http://answers.opencv.org/question/44767/rtsp-link-can-not-open-camera-java-h264-stream/
[3] http://pkgs.org/centos-6/linuxtech/liborc-devel-0.4.14-1.el6.x86_64.rpm.html
[4] http://www.cnblogs.com/foohack/p/4153173.html

文章目录
  1. 1. 测试代码
  2. 2. 报错及解决办法
  3. 3. 添加第三方源